﻿
$(function () {
    //初始化列表信息
    init();
});

//初始化列表信息
function init(queryData) {
    $('#list').datagrid({
        title: '',
        idField: 'AttachmentID',
        fitColumns: 'true',
        autoRowHeight: true,
        singleSelect: true,
        nowrap: true,
        striped: true,
        pagination: false,
        url: '/Attachment/GetList?refID=' + $("#refID").val(),
        columns: [[
			{ field: 'AttachmentID', title: '附件ID', hidden: true },
			{ field: 'ShowName', title: '文件名称', width: 400, resize: true },
			//{ field: 'FolderUrl', title: '网络文件地址', width: 180 },
			//{ field: 'FileName', title: '网络文件存储名称', width: 180 },
			//{ field: 'AttachKind', title: ' 系统上传的附件统一到此表维护', width: 180},
			//{ field: 'DownTimes', title: '下载次数', width: 180},
			{ field: 'CreateByName', title: '创建人', width: 180, resize: true },
			{
			    field: 'CreateTime', title: '创建时间', width: 180, resize: true,
			    formatter: function (value, row, index) {
			        return formatDate(value, "yyyy-MM-dd");
			    }
			},
			//{ field: 'UpdateBy', title: '修改人', width: 180},
			//{ field: 'UpdateTime', title: '修改时间', width: 180},

        ]],
    });
}

//删除
function del() {
    var rows = $('#list').datagrid('getSelected');
    if (rows) {
        $.messager.confirm(delDlgTitle, delDlgMsg, function (r) {
            if (r) {
                $.post('/Attachment/Delete', { id: rows.AttachmentID },
                    function (result) {
                        if (result == 'OK') {
                            $("#list").datagrid('clearSelections');
                            $('#list').datagrid('reload');    // reload the user data  
                        } else {
                            $.messager.show({   // show error message  
                                title: 'Error',
                                msg: result
                            });
                        }
                    });
            }
        });
    }
}

function download() {
    var rows = $('#list').datagrid('getSelected');
    if (rows) {
        $("#downloadFile").attr("href", "/Attachment/DownloadFile?id=" + rows.AttachmentID);
    }
    else {
        $("#downloadFile").attr("href", "#");
    }
}
